#include <bits/stdc++.h>
#define MAXN 200023
#define ll long long
using namespace std;
int cnt, m;
ll d, tmp;
inline ll get_num() {
	ll k = 0, f = 1;
	char c = getchar();
	for(; !isdigit(c); c = getchar()) if(c == '-') f = -1;
	for(; isdigit(c); c = getchar()) k = k * 10 + c - '0';
	return k * f;
}
struct segtree {
	ll mx[MAXN << 2];
	segtree() {
		memset(mx, 0, sizeof(mx));
	}
	void change(int x, int l, int r, int k, ll tmp) {//第k个位置的数值为tmp
		int mid = (l + r) >> 1;
		if(l == r) {
			mx[x] = tmp;
			return;
		}
		else if(k > mid) change(x << 1 | 1, mid + 1, r, k, tmp);
		else if(k <= mid) change(x << 1, l, mid, k, tmp);
		mx[x] = max(mx[x << 1], mx[x << 1 | 1]);
	}
	ll find(int x, int l, int r, int s, int t) {
		int mid = (l + r) >> 1;
		if(l == s && t == r) return mx[x];
		else if(t <= mid) return find(x << 1, l, mid, s, t);
		else if(s > mid) return find(x << 1 | 1, mid + 1, r, s, t);
		else {
			return max(find(x << 1, l, mid, s, mid), find(x << 1 | 1, mid + 1, r, mid + 1, t));
		}
	}
}T;
int main() {
//	freopen("bzoj_1012.in", "r", stdin);
//	freopen("bzoj_1012.out", "w", stdout);
	m = get_num();
	d = get_num();
	while(m--) {
		char type = getchar();
		for(; !isalpha(type); type = getchar());
		if(type == 'Q') {
			int l = get_num();
			tmp = T.find(1, 1, MAXN, cnt - l + 1, cnt);
			printf("%lld\n", tmp);
		}else {
			ll n = get_num();
			n += tmp;
			n %= d;
			T.change(1, 1, MAXN, ++cnt, n);
		}
	}
}
